Passed
Push — master ( 46d449...c17029 )
by Muhammad Dyas
01:28
created

option.js ➔ addOptionToState   A

Complexity

Conditions 2

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 7
dl 0
loc 9
rs 10
c 0
b 0
f 0
1
/**
2
 * Add a new option to the state(like DB)
3
 *
4
 * @param {string} option - the new option name
5
 * @param {object} state - the current message state
6
 * @param {string} creator - who add the new option
0 ignored issues
show
Documentation introduced by
The parameter creator does not exist. Did you maybe forget to remove this comment?
Loading history...
7
 * @returns {void} card
8
 */
9
function addOptionToState(option, state, creator = '') {
10
  const choiceLength = state.choices.length;
11
  state.choices.push(option);
12
  if (state.choiceCreator === undefined) {
13
    state.choiceCreator = {[choiceLength]: creator};
14
  } else {
15
    state.choiceCreator[choiceLength] = creator;
16
  }
17
}
18
19
exports.addOptionToState = addOptionToState;
20